#include<vector>
#include<iostream>
using namespace std;
class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums) {
        vector<int>ans(nums.size(),1);
        for(int i=1;i<ans.size();i++)
        {
            ans[i]=nums[i-1]*ans[i-1];
        }
        int r=1;
        for(int i=ans.size()-1;i>=0;i--)
            {
                ans[i]*=r;
                r*=nums[i];
            }
        return ans;
    }
};